From 63ba48b8076f17ae871f39af2f59fc4a3b9751e4 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Mon, 4 Jul 2005 15:34:57 +0000 Subject: [PATCH] Fix grant-table interface by removing the unnecessary union. This fixes a domU crash introduced over the weekend. Signed-off-by: Keir Fraser --- .../drivers/xen/blkback/blkback.c | 52 ++++++------- tools/libxc/xc_gnttab.c | 75 +++++++++---------- xen/include/public/grant_table.h | 9 --- 3 files changed, 63 insertions(+), 73 deletions(-) diff --git a/linux-2.6.11-xen-sparse/drivers/xen/blkback/blkback.c b/linux-2.6.11-xen-sparse/drivers/xen/blkback/blkback.c index 3b5b7ff2d8..8f78b2376c 100644 --- a/linux-2.6.11-xen-sparse/drivers/xen/blkback/blkback.c +++ b/linux-2.6.11-xen-sparse/drivers/xen/blkback/blkback.c @@ -116,23 +116,23 @@ static void make_response(blkif_t *blkif, unsigned long id, static void fast_flush_area(int idx, int nr_pages) { #ifdef CONFIG_XEN_BLKDEV_GRANT - gnttab_op_t aop[BLKIF_MAX_SEGMENTS_PER_REQUEST]; - unsigned int i, invcount = 0; - u16 handle; + struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST]; + unsigned int i, invcount = 0; + u16 handle; for ( i = 0; i < nr_pages; i++ ) { if ( BLKBACK_INVALID_HANDLE != ( handle = pending_handle(idx, i) ) ) { - aop[i].u.unmap_grant_ref.host_virt_addr = MMAP_VADDR(idx, i); - aop[i].u.unmap_grant_ref.dev_bus_addr = 0; - aop[i].u.unmap_grant_ref.handle = handle; + unmap[i].host_virt_addr = MMAP_VADDR(idx, i); + unmap[i].dev_bus_addr = 0; + unmap[i].handle = handle; pending_handle(idx, i) = BLKBACK_INVALID_HANDLE; invcount++; } } if ( unlikely(HYPERVISOR_grant_table_op( - GNTTABOP_unmap_grant_ref, aop, invcount))) + GNTTABOP_unmap_grant_ref, unmap, invcount))) BUG(); #else @@ -387,21 +387,21 @@ static void dispatch_probe(blkif_t *blkif, blkif_request_t *req) #ifdef CONFIG_XEN_BLKDEV_GRANT { - gnttab_op_t op; + struct gnttab_map_grant_ref map; - op.u.map_grant_ref.host_virt_addr = MMAP_VADDR(pending_idx, 0); - op.u.map_grant_ref.flags = GNTMAP_host_map; - op.u.map_grant_ref.ref = blkif_gref_from_fas(req->frame_and_sects[0]); - op.u.map_grant_ref.dom = blkif->domid; + map.host_virt_addr = MMAP_VADDR(pending_idx, 0); + map.flags = GNTMAP_host_map; + map.ref = blkif_gref_from_fas(req->frame_and_sects[0]); + map.dom = blkif->domid; if ( unlikely(HYPERVISOR_grant_table_op( - GNTTABOP_map_grant_ref, &op, 1))) + GNTTABOP_map_grant_ref, &map, 1))) BUG(); - if ( op.u.map_grant_ref.handle < 0 ) + if ( map.handle < 0 ) goto out; - pending_handle(pending_idx, 0) = op.u.map_grant_ref.handle; + pending_handle(pending_idx, 0) = map.handle; } #else /* else CONFIG_XEN_BLKDEV_GRANT */ @@ -445,7 +445,7 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) int i, pending_idx = pending_ring[MASK_PEND_IDX(pending_cons)]; pending_req_t *pending_req; #ifdef CONFIG_XEN_BLKDEV_GRANT - gnttab_op_t aop[BLKIF_MAX_SEGMENTS_PER_REQUEST]; + struct gnttab_map_grant_ref map[BLKIF_MAX_SEGMENTS_PER_REQUEST]; #else unsigned long remap_prot; multicall_entry_t mcl[BLKIF_MAX_SEGMENTS_PER_REQUEST]; @@ -486,21 +486,21 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) goto bad_descriptor; preq.nr_sects += seg[i].nsec; - aop[i].u.map_grant_ref.host_virt_addr = MMAP_VADDR(pending_idx, i); - aop[i].u.map_grant_ref.dom = blkif->domid; - aop[i].u.map_grant_ref.ref = blkif_gref_from_fas(fas); - aop[i].u.map_grant_ref.flags = GNTMAP_host_map; + map[i].host_virt_addr = MMAP_VADDR(pending_idx, i); + map[i].dom = blkif->domid; + map[i].ref = blkif_gref_from_fas(fas); + map[i].flags = GNTMAP_host_map; if ( operation == WRITE ) - aop[i].u.map_grant_ref.flags |= GNTMAP_readonly; + map[i].flags |= GNTMAP_readonly; } if ( unlikely(HYPERVISOR_grant_table_op( - GNTTABOP_map_grant_ref, aop, nseg))) + GNTTABOP_map_grant_ref, map, nseg))) BUG(); for ( i = 0; i < nseg; i++ ) { - if ( unlikely(aop[i].u.map_grant_ref.handle < 0) ) + if ( unlikely(map[i].handle < 0) ) { DPRINTK("invalid buffer -- could not remap it\n"); fast_flush_area(pending_idx, nseg); @@ -508,9 +508,9 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) } phys_to_machine_mapping[__pa(MMAP_VADDR(pending_idx, i))>>PAGE_SHIFT] = - FOREIGN_FRAME(aop[i].u.map_grant_ref.dev_bus_addr); + FOREIGN_FRAME(map[i].dev_bus_addr); - pending_handle(pending_idx, i) = aop[i].u.map_grant_ref.handle; + pending_handle(pending_idx, i) = map[i].handle; } #endif @@ -518,7 +518,7 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) { fas = req->frame_and_sects[i]; #ifdef CONFIG_XEN_BLKDEV_GRANT - seg[i].buf = (aop[i].u.map_grant_ref.dev_bus_addr << PAGE_SHIFT) | + seg[i].buf = (map[i].dev_bus_addr << PAGE_SHIFT) | (blkif_first_sect(fas) << 9); #else seg[i].buf = (fas & PAGE_MASK) | (blkif_first_sect(fas) << 9); diff --git a/tools/libxc/xc_gnttab.c b/tools/libxc/xc_gnttab.c index 409539cb14..4101ca74dd 100644 --- a/tools/libxc/xc_gnttab.c +++ b/tools/libxc/xc_gnttab.c @@ -11,20 +11,20 @@ #include "xen/grant_table.h" static int -do_gnttab_op( int xc_handle, - unsigned long cmd, - gnttab_op_t *op, - unsigned long count ) +do_gnttab_op(int xc_handle, + unsigned long cmd, + void *op, + unsigned long count) { int ret = -1; privcmd_hypercall_t hypercall; hypercall.op = __HYPERVISOR_grant_table_op; hypercall.arg[0] = cmd; - hypercall.arg[1] = (unsigned long)(op); + hypercall.arg[1] = (unsigned long)op; hypercall.arg[2] = count; - if ( mlock(op, sizeof(*op)) != 0 ) + if ( mlock(op, 64) ) { PERROR("do_gnttab_op: op mlock failed"); goto out; @@ -33,7 +33,7 @@ do_gnttab_op( int xc_handle, if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 ) ERROR("do_gnttab_op: HYPERVISOR_grant_table_op failed: %d", ret); - safe_munlock(op, sizeof(*op)); + safe_munlock(op, 64); out: return ret; } @@ -47,18 +47,19 @@ int xc_gnttab_map_grant_ref(int xc_handle, s16 *handle, memory_t *dev_bus_addr) { - gnttab_op_t op; - int rc; + struct gnttab_map_grant_ref op; + int rc; - op.u.map_grant_ref.host_virt_addr = host_virt_addr; - op.u.map_grant_ref.dom = (domid_t)dom; - op.u.map_grant_ref.ref = ref; - op.u.map_grant_ref.flags = flags; + op.host_virt_addr = host_virt_addr; + op.dom = (domid_t)dom; + op.ref = ref; + op.flags = flags; - if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_map_grant_ref, &op, 1)) == 0 ) + if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_map_grant_ref, + &op, 1)) == 0 ) { - *handle = op.u.map_grant_ref.handle; - *dev_bus_addr = op.u.map_grant_ref.dev_bus_addr; + *handle = op.handle; + *dev_bus_addr = op.dev_bus_addr; } return rc; @@ -71,15 +72,18 @@ int xc_gnttab_unmap_grant_ref(int xc_handle, u16 handle, s16 *status) { - gnttab_op_t op; - int rc; + struct gnttab_unmap_grant_ref op; + int rc; - op.u.unmap_grant_ref.host_virt_addr = host_virt_addr; - op.u.unmap_grant_ref.dev_bus_addr = dev_bus_addr; - op.u.unmap_grant_ref.handle = handle; + op.host_virt_addr = host_virt_addr; + op.dev_bus_addr = dev_bus_addr; + op.handle = handle; - if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_unmap_grant_ref, &op, 1)) == 0 ) - *status = op.u.unmap_grant_ref.status; + if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_unmap_grant_ref, + &op, 1)) == 0 ) + { + *status = op.status; + } return rc; } @@ -90,20 +94,17 @@ int xc_gnttab_setup_table(int xc_handle, s16 *status, memory_t **frame_list) { - gnttab_op_t op; - int rc; - int i; + struct gnttab_setup_table op; + int rc, i; - op.u.setup_table.dom = (domid_t)dom; - op.u.setup_table.nr_frames = nr_frames; + op.dom = (domid_t)dom; + op.nr_frames = nr_frames; if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_setup_table, &op, 1)) == 0 ) { - *status = op.u.setup_table.status; + *status = op.status; for ( i = 0; i < nr_frames; i++ ) - { - (*frame_list)[i] = op.u.setup_table.frame_list[i]; - } + (*frame_list)[i] = op.frame_list[i]; } return rc; @@ -113,15 +114,13 @@ int xc_gnttab_dump_table(int xc_handle, u32 dom, s16 *status) { - gnttab_op_t op; - int rc; + struct gnttab_dump_table op; + int rc; - op.u.dump_table.dom = (domid_t)dom; - - printf("xc_gnttab_dump_table: domain %d\n", dom); + op.dom = (domid_t)dom; if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_dump_table, &op, 1)) == 0 ) - *status = op.u.dump_table.status; + *status = op.status; return rc; } diff --git a/xen/include/public/grant_table.h b/xen/include/public/grant_table.h index fb2f3f5b14..d5c7d4715f 100644 --- a/xen/include/public/grant_table.h +++ b/xen/include/public/grant_table.h @@ -259,13 +259,4 @@ typedef struct gnttab_dump_table { "permission denied" \ } -typedef struct gnttab_op { - union { - gnttab_map_grant_ref_t map_grant_ref; - gnttab_unmap_grant_ref_t unmap_grant_ref; - gnttab_setup_table_t setup_table; - gnttab_dump_table_t dump_table; - } u; -} gnttab_op_t; - #endif /* __XEN_PUBLIC_GRANT_TABLE_H__ */ -- 2.30.2